<template>
    <div class="is-array"></div>
</template>
<script setup lang="ts">
const arr = [1, 2, 3]
const str = 'array'
const isArray = (obj: any) => {
    return Object.prototype.toString.call(obj) === '[object Array]'
}
const isArray2 = (obj: any) => {
    return Array.isArray(obj)
}
const isArray3 = (obj: any) => {
    return obj.constructor === Array
}
const isArray4 = (obj: any) => {
    return obj instanceof Array
}
const customArr = function (...args: any[]) {
    Array.call(this, ...args)
    // this.num = num
    // this.constructor = Array
    // this.prototype = new Array(num)
}
// customArr.constructor = Array
// customArr.prototype = new Array()
// customArr.prototype.constructor = Array
const obj = {
    arr: [1, 2, 3],
    str: 'array',
    customObj: new customArr(2),
    isArray: isArray,
    isArray2: isArray2,
    isArray3: isArray3,
    isArray4: isArray4,
    getStr() {
        return this.str
    }
}
const funs: string[] = ['isArray', 'isArray2', 'isArray3', 'isArray4']
funs.forEach((item) => {
    // 's'.includes
    console.log('arr'.padEnd(10, ' '), obj[item](obj.arr))
    console.log('str'.padEnd(10, ' '), obj[item](obj.str))
    console.log('customObj'.padEnd(10, ' '), obj[item](obj.customObj))
})

// obj.customObj.push(123)
// obj.customObj.push('123')
console.log(obj.arr)
console.log(obj.customObj)

</script>
<style lang="scss" scoped>
.is-array {
}
</style>
